import {useState, useCallback} from 'react';

interface ToastState {
    message: string;
    type: 'error' | 'success' | 'warning';
}

export function useToast(){
    const [toast, setToast] = useState<ToastState | null>(null);

    const showToast = useCallback((message:string, type:ToastState['type'] = 'error') => {
        setToast({message, type});
    },[]);

    const hideToast = useCallback(() => {
        setToast(null);
    },[]);

    return{
        toast,
        showToast,
        hideToast
    };
}